
from unittest import TestCase
from ddt  import ddt,data,unpack
import time
from selenium import webdriver
from LoginOperation import LoginOperation
from Login_data import Login_data




@ddt
class Test1Login(TestCase):


    @data(*Login_data.login_success_data)
    @unpack
    def testLogin1(self,name,pwd,expect,case):

        # 测试前条件准备
        # DBUtils.update("delete from user  where username = '张三'")

        #  开始测试
        driver = webdriver.Chrome()

        driver.get("http://localhost:90")
        driver.maximize_window()

        log = LoginOperation()
        log.login(driver,name,pwd)

        result = log.getSuccessResult(driver)


        # 用于数据验证也可以用DBUtils
        # data = DButils.select("select * from user where username = %s",[name])

        # if data != None:
        #     print("通过！")
        # else:
        #     driver.save_screenshot(name + pwd + ".jpg")


        if result != expect:
            driver.save_screenshot(f'D:/Users/北极星的眼泪/Desktop/demo/自动化测试第三四天/报错截图/{case}.png')
        else:
            print("通过")

        driver.quit()

        self.assertEqual(expect,result)


    @data(*Login_data.login_name_Error_data)
    @unpack
    def testLogin2(self,name,pwd,expect,case):

        driver = webdriver.Chrome()

        driver.get("http://localhost:90")
        driver.maximize_window()

        log = LoginOperation()
        log.login(driver,name,pwd)

        result = log.getNameErrorResult(driver)

        if result != expect:
            driver.save_screenshot(f'D:/Users/北极星的眼泪/Desktop/demo/自动化测试第三四天/报错截图/{case}.png')
        else:
            print("通过")

        driver.quit()

        self.assertEqual(expect,result)

    @data(*Login_data.login_pwd_error_Data)
    @unpack
    def testLogin3(self,name,pwd,expect,case):

        driver = webdriver.Chrome()

        driver.get("http://localhost:90")
        driver.maximize_window()

        log = LoginOperation()
        log.login(driver,name,pwd)

        result = log.getPwdErrorResult(driver)

        if result != expect:
            driver.save_screenshot(f'D:/Users/北极星的眼泪/Desktop/demo/自动化测试第三四天/报错截图/{case}.png')
        else:
            print("通过")

        driver.quit()

        self.assertEqual(expect,result)















